package com.sw.funfuck.discuss.controller;

import com.sw.funfuck.common.enums.DiscussDataSetEnum;
import com.sw.funfuck.common.vo.PageResponse;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import com.sw.funfuck.common.common.GlobalException;
import org.springframework.web.bind.annotation.RestController;
import com.sw.funfuck.discuss.service.DiscussService;
import com.sw.funfuck.discuss.vo.response.DiscussQueryListResponse;
import com.sw.funfuck.discuss.vo.request.DiscussQueryRequest;

/**
 * @Desc: 论坛组API
 *
 * 1.查询论坛组帖子列表
 * 2.查询讨论组详情
 * 3.更新讨论组的信息
 * 4.删除讨论组以及相关数据
 * 5.增加讨论组
 * ====
 * 6.插入{@link DiscussDataSetEnum } 数据集去讨论组
 * 7.
 * @Author: wusonghe
 * @Date: 2019/3/4 15:26
 */

@Api(value = "论坛组模块", description = "论坛组模块", tags = {"Discuss Module"})
@RestController("/discuss/")
public class DiscussController {

    private static final Logger logger = LoggerFactory.getLogger(DiscussController.class);


    @Autowired
    private DiscussService discussService;

    @GetMapping("/list")
    @ApiOperation(value = "分页查询论坛帖子接口", notes = "分页查询论坛帖子", response = DiscussQueryListResponse.class)
    @ApiResponses({@ApiResponse(code = 200, message = "分页结果结构", response = PageResponse.class),
            @ApiResponse(code = 201, message = "列表详情", response = DiscussQueryListResponse.class)})
    public ResponseEntity<?> queryDiscussList(@ApiParam @ModelAttribute DiscussQueryRequest queryRequest)
            throws GlobalException {

        try {

            PageResponse pageResponseData = discussService.queryDiscussList(queryRequest);

            return new ResponseEntity<>(pageResponseData, HttpStatus.OK);

        } catch (Exception e) {

            logger.error("queryDiscussList", e);
            throw new GlobalException("/discuss/list", e.getMessage());
        }

    }
}
